<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>

    <style>
      div {
        width: 200px;
        height: 100px;
        position: relative;
        background-color: blueviolet;
      }
      #btn {
        position: absolute;
        right: 0;
        top: 0;
      }
    </style>
  </head>

  <body>
    <div class="box">
      <button id="btn">点击关闭</button>
    </div>
    <script>
      var boxEle = document.querySelector(".box");
      var btnEle = document.getElementById("btn");
      var flag = true;
      document.onclick = function () {
        setTimeout(function () {
          boxEle.style.display = "none";
        }, 500);
        setTimeout(function () {
          boxEle.style.display = "block";
        }, 1000);
      };
    </script>
  </body>
</html>
